package com.lcb.bio;

import java.io.IOException;
import java.net.Socket;

/****
 * @Author:刘长柏
 * @Date: 2021-02-19 10:13
 * @Description: socket 客户端
 *****/
public class SocketClient {
    public static void main(String[] args) throws IOException {

            Socket socket = new Socket("localhost", 9000);
            //向服务器发送数据
            socket.getOutputStream().write("HelloServer".getBytes());
            socket.getOutputStream().flush();
            System.out.println("向服务器发送数据结束");
            byte[] bytes = new byte[4];

            //接收服务器回传的数据
            socket.getInputStream().read(bytes);
            System.out.println("接收服务器端数据: " + new String(bytes));
            socket.close();
    }
}
